import Taro, {Component} from '@tarojs/taro'
import {View, Button, Text, Swiper, SwiperItem, Image, ScrollView} from '@tarojs/components'
import {connect} from '@tarojs/redux'
import {
  set_userinfo, set_cart, set_goodslist, set_viplist, set_bind_car_num, set_progress,
  set_pushdata, set_pushdatanum, gohome_btn, set_cart_num,
} from '../../actions/IndexAction'
import base from "../base"
import { AtTabs, AtSearchBar,AtAvatar } from 'taro-ui'
import './index.less'
import set from "../../apis/api"
var search_page=1;
class bar extends Component {
  constructor(props) {
    super(props)
    base(this)
    this.state = {
      jzlist:[],
      value:"",
    }
  }

  config = {
    navigationBarTitleText: '新图表',
    enablePullDownRefresh: true,
    navigationBarBackgroundColor: "#4bb33d",
    navigationBarTextStyle: "white"

  }

  onReachBottom() {
    this.subSearch()


  }


  componentWillReceiveProps(nextProps) {
    console.log(this.props, nextProps)
  }

  onPullDownRefresh() {



    wx.stopPullDownRefresh();
  }

  componentWillUnmount() {
  }

  componentDidShow() {
    this.onPullDownRefresh()


  }

  toJZDetail(item)
  {

    Taro.navigateTo({
      url: '/pages/gypage/jz_detail?item='+JSON.stringify(item)
    })

  }

  subSearchClick()
  {
    search_page=1;
    this.setState({
      jzlist:[]
    },()=>{
      this.subSearch()
    })


  }
  subSearch() {



    wx.showLoading({title: "加载中..."})
    var databody = {
      wxid:this.props.sys_config.sets.wxid,
      access_token: this.props.gytoken.gytoken,
      I_name:this.state.value,
      page:search_page,
      // jd:this.props.location.longitude,
      // wd:this.props.location.latitude,
      // scope:set.scope
    }
    console.log(databody)
    this.wx_request(set.get_page, databody, "POST", {'Content-Type': 'application/x-www-form-urlencoded'}).then((res) => {
      console.log("search",res.data.data.data)
      if(res.data.data.data)
      {
        search_page++;
        this.setState({
          jzlist:this.state.jzlist.concat(res.data.data.data)
        })
      }

      wx.hideLoading();
      wx.stopPullDownRefresh()
    })

  }

  changeValue(val)
  {
    this.setState({
      value:val
    })
  }



  componentDidHide() {
  }

  render() {
    const {jzlist}=this.state;
    return (
      <View style={{background:"#f0f2f5",minHeight:"100vh",padding:"30rpx"}}>
        <View style={{width:"100%",height:"100rpx",borderBottom:"1px solid #333333",borderLeft:"1px solid #333333",display:"flex",alignItems:"center",position:"relative"}}>
          <View style={{width:"100%",height:"60rpx",background:"#cccccc",display:"flex"}}>
            <View style={{width:"1%",background:"#cc0033",height:"100%"}}>
            </View>
            <View style={{width:"1%",background:"#cc0033",height:"100%"}}>
            </View>
            <View style={{width:"1%",background:"#cc0033",height:"100%"}}>
            </View>
            <View style={{width:"1%",background:"#ffffff",height:"100%"}}>
            </View>
            <View style={{width:"1%",background:"#cc0033",height:"100%"}}>
            </View>
          </View>
          <View style={{width:"100%",height:"6rpx", position:"absolute",bottom:"0",display:"flex"}}>
            <View style={{width:"1%", height:"100%",borderRight:"1px solid #333333"}}>
            </View>
            <View style={{width:"1%", height:"100%",borderRight:"1px solid #333333"}}>
            </View>
            <View style={{width:"1%", height:"100%",borderRight:"1px solid #333333"}}>
            </View>
            <View style={{width:"1%", height:"100%",borderRight:"1px solid #333333"}}>
            </View>

          </View>

        </View>

      </View>
    )
  }
}

const mapstate = state => {
  return {
    userinfo: state.usermodel,
    cart_num: state.cart_num,
    cart: state.cart,
    goodslist: state.goodslist,
    vip: state.vip,
    progress: state.progress,
    pushdata: state.pushdata,
    wxuser: state.wxusermodel,sys_config:state.sys_config,
    gytoken:state.gytoken,
    location:state.location,
  }
}
export default connect(mapstate)(bar)

